import java.util.*;
/**
* Catch invalid input
 * 
 * "10" is valid (enter "10" without the quotes)
 * "ten" is invalid (enter "ten" without the quotes)
 * 
 * @author Amrita Mukherjee 
 * @version 10/16/2012
 */
public class CatchInvalidInput
{
    public static void main(String[] args)
    {
       //create a scanner object
       Scanner kb = new Scanner(System.in);
       
       //prompt the user
       System.out.print("How old are you? ");
       
       //try to input an integer
       int age;
       try{
           //if nextInt() doesnt find an integer it 'throws' an exception
           age = kb.nextInt();
           //if execution reached here , the input must have been an integer
        }
        //catch error thrown by nextInt()
        catch(InputMismatchException exception){
            // input is apparently not an integer
            System.out.println("You did not enter an integer!");
            return;
        }
       System.out.println("You entered: " + age);
      
       
    }
}
/*
 * my test session:
 * How old are you? ten
You did not enter an integer!

 */